home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-10-12 | 4.9 KB | 154 lines | [TEXT/GEOL] |
- Item 6759812 12-Oct-89 03:10
-
- From: AU0008 Kopfwerk EDV SW Entwicklung
-
- To: MACAPP.TECH$ MACAPP Tech
-
- cc: D2652 Strategic Planning Sys, D Bell,PRT
-
- Sub: RE: WindowMenu
-
- Don,
- here is my receipe for a windows menu. It is a modification of an articel in a
- pre-FrameWorks. I use it in my application and it works with 2.0b9. The window
- menu is a hierarchical menu.
-
- >In the interface part declare following constants:
- CONST
- cChooseWind = 3000; { command menu number for dis/enabling }
- mWindowsMenu = 17; { menuID for hier. windows menu }
-
- >Add a new field to your application class and override two methods:
-
- TYourApplication = OBJECT(TApplication)
- fWindowMenuList : TList; (* needed for a window menu *)
- PROCEDURE TYourApplication.IApplication;
- PROCEDURE TYourApplication.DoSetUpMenus; OVERRIDE;
- FUNCTION TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber):
- TCommand; OVERRIDE;
- (* your fields and methods… *)
- END;
-
- >In the TYourApplication.IYourApplication method initialize the list
-
- fWindowMenuList:= NewList;
-
- >Implementation of DoSetUpMenus and DoMenuCommand
-
- {$S ARes}
- PROCEDURE TYourApplication.DoSetUpMenus; OVERRIDE;
- VAR
- theWindowsMenu : MenuHandle;
- item, j : INTEGER;
- title : str255;
-
- PROCEDURE AddToWindowsMenu(aWindow: TWindow);
- BEGIN
- if (aWindow <> gClipWindow) & aWindow.isShown then
- { don´t add clipboard and invisible windows }
- BEGIN
- GetWTitle(aWindow.fWmgrWindow, title);
- AppendMenu(theWindowsMenu, title); { add the title to the real menu }
- fWindowMenuList.InsertLast(aWindow);
- { add it also to our description of the real word }
- item:= succ(item);
- EnableItem(theWindowsMenu, item); { enable this new item }
- if aWindow = GetActiveWindow then
- { the item of the frontwindow will be marked }
- SetItemMark(theWindowsMenu, item, chr(diamondMark));
- END;
- END;
-
- BEGIN
- INHERITED DoSetUpMenus;
-
- (* enable your favorite items here *)
-
- theWindowsMenu:= GetMHandle(mWindowsMenu);
- for j:= 1 to CountMItems(theWindowsMenu) do { remove all old items }
- DelMenuItem(theWindowsMenu, 1);
- fWindowMenuList.DeleteAll; { remove also our descriptions }
- { of the real menu world }
-
- item:= 0; { initialize the counter of items we will append }
- ForAllWindowsDo(AddToWindowsMenu); { append all windowtitles to the menu }
- Enable(cChooseWind, item > 0);
- { enable the menu in case of submenuitems exist }
- END;
-
-
- {$S ASelCommand}
- FUNCTION TYourApplication.DoMenuCommand (aCmdNumber: CmdNumber):
- TCommand; OVERRIDE;
- VAR
- menu, menuItem, i : INTEGER;
- newFrontWindow : TWindow;
- theWindowsMenu : MenuHandle;
- aLong : LongInt;
-
- BEGIN
- DoMenuCommand:= gNoChanges;
- CASE aCmdNumber OF
- (* here are your special command numbers *)
- (* e.g.: cHelp: BEGIN …… *)
-
- OTHERWISE
- BEGIN
- if aCmdNumber < 0 then
- { dynamic command numbers are negative! }
- BEGIN
- CmdToMenuItem(aCmdNumber, menu, menuItem);
- if menu = mWindowsMenu then { user chooses a window }
- BEGIN
- newFrontWindow:= TWindow(fWindowMenuList.At(menuItem));
- if newFrontWindow <> GetActiveWindow then
- { situation changed? }
- SelectWindow(newFrontWindow.fWmgrWindow);
- DoMenuCommand:= gNoChanges;
- END ELSE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END ELSE
- DoMenuCommand:= INHERITED DoMenuCommand (aCmdNumber);
- END;
- END;
- END;
-
- >In your resource description file create a hierarchical window menu without
- >items in it.
-
- #define cChooseWind 3000
-
- resource 'cmnu' (2) {
- 2,
- textMenuProc,
- 0x7FFFFBAF,
- enabled,
- "File",
- {
- // place you favorite items here
-
- // add a hierarchical window menu
- "Choose Window", noIcon, "\0x1B", "\0x11", plain, cChooseWind;
-
- "-", noIcon, noKey, noMark, plain, nocommand;
- "Quit", noIcon, "Q", noMark, plain, cQuit
- }
- };
-
-
- resource 'cmnu' (17) {
- 17,
- textMenuProc,
- 0x7FFFFFF7,
- enabled,
- "Choose Window",
- { }
- };
-
- Hope this helps,
- kind regards,
-
- Tommi GESSL,
- KOPFWERK SW. Dev.
-
-